package com.tanhua.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.mapper.UserMapper;
import com.tanhua.sso.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@DubboService
public class UserServiceImpi implements UserService{

    //查询
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByPhone(String phone) {
        LambdaQueryWrapper<User> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getMobile,phone);
        User user = userMapper.selectOne(lambdaQueryWrapper);
        return user;
    }

    //新增
    @Override
    public void save(User user) {
        userMapper.insert(user);
    }

    //修改
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long valueOf) {
        User user = userMapper.selectById(valueOf);
        return user;
    }

    @Override
    public User selectByHuanXinId(String huanxinId) {
        LambdaQueryWrapper<User> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getHxUser,huanxinId);
        User user = userMapper.selectOne(lambdaQueryWrapper);
        return user;
    }

    /*修改手机号*/
    @Override
    public void selectPhone(Long userId, String phone) {
        User user = userMapper.selectById(userId);
        user.setMobile(phone);
        user.setUpdated(new Date());
        userMapper.updateById(user);
    }
}
